/*
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file activity.cpp
 * @author Marco Buzzanca 
 *
 * This file contains Activity class implementation.
 */

#include "activity.h"

Activity::Activity(const Workflow& wf, const WorkerNetwork& sbn )
  : _wf(wf), _sbn(sbn) { }

Activity::~Activity(void) { }

const Workflow& Activity::getWf(void) const
{ return _wf; }

void Activity::setWf(const Workflow& wf)
{ _wf = wf; }

const WorkerNetwork& Activity::getSbn(void) const
{ return _sbn; }

void Activity::setSbn(const WorkerNetwork& sbn)
{ _sbn = sbn; }

void Activity::scheduleActivity()
{
  t_queue_manager_proxy_t tqmp = _tqpf.getProxy();
  size_t sbn_i;

  for (size_t i = 0; i < _wf.size(); i++)
  {
    // If there are less workers than tasks in workflow, restart from the
    // first worker.
    sbn_i = i % _sbn.size();

    tqmp->setAddr(_sbn.getWorker(sbn_i));
    tqmp->enqueue(_wf.getTask(i));
  }
}
